/**
 *
 * @Copyright (c) 2015 Messcat. All rights reserved.
 */
package cc.messcat.service.system;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cc.messcat.common.service.BaseServiceImpl;
import cc.messcat.dao.system.PermissionDao;
import cc.messcat.entity.system.Permission;
import cc.messcat.util.Collections;

/**
 * @author Panda
 * @version 1.0
 */
@Service
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements PermissionService {

	@Autowired
	private PermissionDao permissionDao;

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * cc.messcat.service.system.PermissionService#addPermission(cc.messcat.
	 * entity.system.Permission)
	 */
	@Override
	public void addPermission(Permission permission) {
		addObject(permission);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * cc.messcat.service.system.PermissionService#modifyPermission(cc.messcat.
	 * entity.system.Permission)
	 */
	@Override
	public void modifyPermission(Permission permission) {
		modifyObject(permission);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * cc.messcat.service.system.PermissionService#removePermission(java.lang.
	 * Long)
	 */
	@Override
	public void removePermission(Long id) {
		removeObject(id);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * cc.messcat.service.system.PermissionService#retrievePermissionById(java.
	 * lang.Long)
	 */
	@Override
	public Permission retrievePermissionById(Long id) {
		return retrieveObject(id);
	}

	@Override
	public List<Permission> retrievePermissionAll() {
		return retrieveAllObjects();
	}

	/* (non-Javadoc)
	 * @see cc.messcat.service.system.PermissionService#retrievePermissionMenu()
	 */
	@Override
	public List<Permission> retrievePermissionMenu() {
		return permissionDao.findMenu();
	}

	@Override
	public List<Permission> retrieveSubPermissionOptions(Long id) {
		return permissionDao.findSubOptions(id);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Permission getPermissionByURI(String uri) {
		
		List<Permission> list = permissionDao.queryList(" from Permission where uri= :uri",Collections.generateHashMap(new String[]{"uri"}, uri));
		if(!Collections.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

}
